<?php
	get_header();
        $args = array(
            'type'                     => 'post',
            'child_of'                 => 0,
            'parent'                   => '',
            'orderby'                  => 'name',
            'order'                    => 'ASC',
            'hide_empty'               => 1,
            'hierarchical'             => 1,    	
            'include'                  => '',
            'number'                   => '',
            'taxonomy'                 => 'category',
            'pad_counts'               => false,
            'exclude'                  => 1
        );
        $cats = get_categories($args);
?>
<div id="all-deals">
    <h1 id="inner-title"> Deals in future</h1>
    <hr/>
    <div class="categories-menu">
        <?php 
            $link_all_deals = site_url('/coming-soon');
        ?>
        <span class=""><a class="list-by-category" href="<?php echo $link_all_deals;?>" title="See all deals">All Deals</a></span>
        <?php
            foreach ($cats as $c) {
               $cat_name = $c->name;
               $cat_id = $c->term_id;
               echo "<span class=''><a class='list-by-category' title='See all deals of {$cat_name}' href='$link_all_deals?category=$cat_id'>$cat_name</a></span>";
            }
        ?>
    </div>
    <hr/>
    <?php
        if(!$_GET['category']){
            $row_display = get_option('number_row_all_deal');
            $display = $row_display*4;
            if($row_display == ''){
                $display = 16;
            }
            cpx_get_deals('',$display,1,'deactive',1);
        }else{
            $deactive_deals_ids_by_cat = cpx_get_comming_soon_deals($_GET['category']);
            ?>
                <div class="all-deals-list row-fluid">
                <?php 
                if(count($deactive_deals_ids_by_cat) > 0)
                    {
                        $row_display = get_option('number_row_coming_soon');
                        $display = $row_display*4;
                        if($row_display == ''){
                            $display = 16;
                        }
                        pagination_jquery($deactive_deals_ids_by_cat,0,1,0,$display);
                    } else{ ?>
                    <p class="not-found">Sorry! No deal found.</p>
                   <?php $today = date('Y/m/d');
                    $args = array(
                                'post_type' => 'post',
                                'post_status' =>'publish',
                                'posts_per_page' => 20,
                                'post__not_in' => get_option('sticky_posts'),
                                'meta_key' => 'start_date_metadata',
                                'orderby' => 'start_date_metadata',
                                'order' => 'DESC',
                                'meta_query' =>array(
                                    'relation' => 'AND',
                                    array(
                                        'key' => 'start_date_metadata',
                                        'value' => $today,
                                        'compare' => '>'
                                    ),
                                    array(
                                        'key' => 'status_metadata',
                                        'value' => 'deactive',
                                        'compare' => '='
                                    )
                                )
                            );
                            $query = new WP_Query($args);
                            if($query->have_posts()){ ?>
                            <p class="not-found">The followings are upcoming deals:</p>
                                <?php foreach ($query->posts as $p){
                                    cpx_get_deal_info($p->ID, 1, 0, '', 1);
                                }
                            }else{ ?>
                                <span>Please go <a href="<?php echo site_url();?>"> FindsDeals.com</a>  to see a lot of the lastest deals.</span>
                            <?php }
                } ?>
                </div>    
       <?php }
    ?>
</div>
<?php
	get_footer();
?>